import * as fgui from "fairygui-cc";

export class FUIHelper {

    static isClicked = false;

    public static extention() {
        fgui.GButton.prototype.onClickAsync = function (action: Function, target: any): void {
            FUIHelper.onClickAsync(this, action, target);
        };
    }

    public static onClickAsync(button: fgui.GButton, action: Function, target: any) {
        let clickFunctionAsync = async function () {
            FUIHelper.isClicked = true;
            console.log("before action");
            await action.call(target);
            console.log("after action");
            FUIHelper.isClicked = false;
        };
        button.onClick(() => {
            console.log("before click");
            if (FUIHelper.isClicked) {
                console.log("cancel click");
                return;
            }
            console.log("begin click");
            clickFunctionAsync().then();
            console.log("end click");
        }, target);
    }

}